<?php

namespace app\adminmini\service;


use think\facade\Db;
use app\adminmini\model\Meituan;

class MeituanService extends BaseService
{
    public function __construct()
    {
        $this->model = new Meituan();
    }


    public function getUserInfo()
    {

        $info = Db::name('customer_meituan_config')->where('store_id', $this->userId())->find();
        $redirect_url = "";
        $httptype = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';

        $redirect_url = $httptype . $_SERVER['HTTP_HOST'] . "/meituan/getsession";
        if (!$info) {
            $url = "https://e.dianping.com/dz-open/merchant/auth";
            $info['appkey'] = '';
        } else {
            $url = "https://e.dianping.com/dz-open/merchant/auth";
            if ($info['appkey']) $url .= "?admin_id=" . $this->userId() . "&app_key=" . $info['appkey'] . "&redirect_url=" . $redirect_url . "?admin_id=" . $this->userId() . "&state=teststate";


        }
        $info['url'] = $url;
        $info['murl'] = 'http://adminminiqixuke.qishenghui.net/meituan/getsession';
        return message("操作成功", true, $info);
    }

    public function updateUserInfo()
    {

        // 参数
        $data = request()->param();

        $data['store_id'] = $this->userId();

        return parent::edit($data); // TODO: Change the autogenerated stub
    }
}